<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" lang="UTF-8">
<head>
    <meta charset="UTF-8">
    <title> XXX送水公司后台管理系统</title>

    <!--Bootstrap固定框架-->
    <link rel='stylesheet' th:href="@{/webjars/bootstrap/3.3.7/css/bootstrap.css}">
    <link rel='stylesheet' th:href="@{/webjars/bootstrap/3.3.7/css/bootstrap-theme.css}">
    <!--图标库-->
    <link rel='stylesheet' th:href='@{/css/material-design-iconic-font.min.css}'>
    <!--核心样式-->
    <link rel="stylesheet" th:href="@{/css/style.css}">
    <script src="/webjars/jquery/3.3.1/jquery.js"></script>
    <script>
        $(function () {
            $("span[id=add]").click(function () {
                let wid = $(this).prop("class");
                let workerSalary = $(this).next().text();
                // console.log(wid+"------"+workerSalary);
                //数据前端回显
                let salary = parseInt(workerSalary);
                salary+=100;
                $(this).next().text(salary)
                //异步更新
                $.ajax({
                    url:"/worker/adjustSalary",
                    data:{"wid":wid,"workerSalary":salary},
                    method:"POST",
                    success:function (data,status) {
                        if("success" == data){
                            alert("更新工资成功~");
                        }else{
                            alert("更新工资失败~");
                        }
                    }
                })
            })

            $("span[id=sub]").click(function () {
                //获取前端数据
                let wid = $(this).prop("class");
                let workerSalary = $(this).prev().text();
                // console.log(wid+"------"+workerSalary);
                //前端数据回显
                let salary = parseInt(workerSalary);
                salary-=100;
                $(this).prev().text(salary);
                //ajax异步更新
                $.ajax({
                    url: "/worker/adjustSalary",
                    data: {"wid":wid,"workerSalary":salary},
                    method: "POST",
                    success:function (data,status) {
                        if("success" == data){
                            alert("更新工资成功~")
                        }else {
                            alert("更新工资失败~")
                        }
                    }
                })
            })


        })

    </script>
</head>
<body>

<div id="viewport" >

    <!-- Sidebar -->
    <div id="sidebar" th:replace="waterMainMenu::sidebar">
        <header>
            <a href="#">公司后台管理</a>
        </header>
        <ul class="nav">
            <li>
                <a >
                    <i class="zmdi zmdi-view-dashboard"></i> 客户管理
                </a>
            </li>
            <li>
                <a>
                    <i class="zmdi zmdi-link"></i> 送水工管理
                </a>
            </li>
            <li>
                <a>
                    <i class="zmdi zmdi-widgets"></i> 送水历史管理
                </a>

        </ul>
    </div>

    <!-- Content -->
    <div id="content" >
        <nav class="navbar navbar-default" th:replace="waterMainMenu::navbar">
            <div class="container-fluid" >
                <ul class="nav navbar-nav navbar-right">
                    <li>
                        <a href="#"><i class="zmdi zmdi-notifications text-danger"></i>
                        </a>
                    </li>
                    <li><a href="#">测试用户123</a></li>
                </ul>
            </div>
        </nav>
        <div class="container-fluid">
            <div class="row">
                <div class="col-md-4">
                    <a type="button" class="btn btn-warning" th:href="@{/worker/addWorkerPre}">添加工人</a>
                </div>

                <div class="col-md-8">
                    <form class="form-inline" th:action="@{/worker/searchWorker}">
                        <div class="form-group">
                            <input type="text" class="form-control" name="workerName" placeholder="请输入工人名">
                        </div>
                        <input type="button" class="btn btn-info" value="提交">
                    </form>
                </div>


                <div class="col-md-12">
                    <table class="table table-hover table-striped">
                        <thead>
                        <tr>
                            <td>工人编号</td>
                            <td>工人名称</td>
                            <td>工人底薪</td>
                            <td>工人提成</td>
                            <td>图片地址</td>
                            <td>操作</td>
                        </tr>
                        </thead>
                        <tbody>
                            <!-- 渲染后客户列表-->
                            <tr th:each="worker:${workerList}">
                                <td th:text="${worker.wid}"></td>
                                <td th:text="${worker.workerName}"></td>
<!--                                <td th:text="${worker.workerSalary}"></td>-->
                                <td>
                                    <span id="add" th:class="${worker.wid}" style="font-size: 20px;color: hotpink">+</span>
                                    <span th:text="${worker.workerSalary}"></span>
                                    <span id="sub" th:class="${worker.wid}" style="font-size: 30px;color: hotpink">-</span>
                                </td>
                                <td th:text="${worker.workerMoney}"></td>
                                <td th:text="${worker.workerImage}"></td>
                                <td>
                                    <a type="button" class="btn btn-primary" th:href="@{'/worker/modWorkerPre/'+${worker.wid}}" >修改</a>
                                    <a type="button" class="btn btn-danger" th:href="@{'/worker/delWorker/'+${worker.wid}}" >删除</a>
                                </td>
                            </tr>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>


</body>
</html>